// pages/index/Mymessage/message.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
phone:"15978071678",
modifyDialog:true,
mylist:{
  username:"",
},
fileList: "",

myfileList:[{
  url:"",
  isImage: true,
}],
confirmpassword:"",
password:{
  oldpassword:"",
  newpasswore:"",
},
list:{
  replenish:"",
  detailed:"",
  location:"",
},
status:'',

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //调用弹窗组件
this.setData({
  phone:wx.getStorageSync('phone')
})
   
    this.dialog = this.selectComponent("#dialog");
    //根据手机号获取个人信息
    let that=this
    let phone = options.phone ;
   that.data.phone =phone 
   console.log( that.data.phone )
    wx.request({
      url: '',
      method:"POST",
      header:{
        // "cookie":wx.getStorageSync('sessionid'),
    
        "Authorization":wx.getStorageSync('session')
      }, 
     data:{
       "phone ":phone ,
     },
     success (res) {
      that.data.list=res.data.list


      // console.log(res)
  
    }
    })
  },
  _success() {
    this.dialog.hidedialog();
    this.setData({
      modifyDialog:true,
    })
  },
  delete(event) {
this.setData({
  fileList:""
})
  },
  afterRead(event) {
    let that = this
    that.data.myfileList[0].url= event.detail.file.path
    this.setData({
      fileList:that.data.myfileList
    })
    console.log(that.data.fileList)
    const { file } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式

  },
  modify:function(){
    
    let that=this
    let confirmpassword=that.data.confirmpassword
    let newpassword=that.data.password.newpasswore
if (confirmpassword!="") {
if (confirmpassword==newpassword) {
  wx.request({
    url: '',
    method:"POST",
    header:{
      "cookie":wx.getStorageSync('sessionid'),
    }, 
   data:{
     password:that.data.password,
     list:that.data.list,
   },
   success (res) {
    console.log(res)
    that.data.status=res.data.status
  }
  })

  wx.uploadFile({
    url: 'http://192.168.0.104:8888/weibo/fileUpload', 
    filePath: file.path,
    token:that.data.token,
    header:{
      "cookie":wx.getStorageSync('sessionid'),
      'Content-Type': 'multipart/form-data',
      'Authorization': wx.getStorageSync("access_token"), 
    }, 
    name: 'file',
    formData: { user: 'test' },
    success(res) {
      console.log(res)
      that.data.status=res.data.status
      // 上传完成需要更新 fileList
      // const { fileList = [] } = this.data;
      // fileList.push({ ...file, url: res.data });
      // this.setData({ fileList });
    },
  });
  //返回值
  if (that.data.status=="1") {
    this.dialog.showdialog();
    this.setData({
      modifyDialog:false,
      state:"修改成功"
    })
  } else {
    this.dialog.showdialog();
    this.setData({
      modifyDialog:false,
      state:"修改失败"
    })
  }
} else {
  //两次密码不同弹窗
  this.dialog.showdialog();
  this.setData({
    modifyDialog:false,
    state:"两次密码不一致"
  })
}
}else {
  wx.request({
    url: '',
    method:"POST",
    header:{
      "cookie":wx.getStorageSync('sessionid'),
    }, 
   data:{
     list:that.data.list,
   },
   success (res) {
    console.log(res)
    that.data.status=res.data.status
  }
  })
  wx.uploadFile({
    url: 'http://192.168.0.104:8888/weibo/fileUpload', 
    filePath: that.data.fileList,
    header:{
      // "cookie":wx.getStorageSync('sessionid'),
      // 'Content-Type': 'multipart/form-data',
      // 'Authorization': wx.getStorageSync("access_token"), 
    }, 
    data:{
      list:that.data.list,
    },
    name: 'file',
    formData: { user: 'test' },
    success(res) {
      console.log(res)
      // 上传完成需要更新 fileList
      // const { fileList = [] } = this.data;
      // fileList.push({ ...file, url: res.data });
      // this.setData({ fileList });
    },
  });
  if (that.data.status=="1") {
    this.dialog.showdialog();
    this.setData({
      modifyDialog:false,
      state:"修改成功"
    })
  } else {
    this.dialog.showdialog();
    this.setData({
      modifyDialog:false,
      state:"修改失败"
    })
  }
}
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})